//
//  CityDetailVC.m
//  Project
//
//  Created by 冯东辉 on 2018/9/28.
//  Copyright © 2018年 FengDongHui. All rights reserved.
//

#import "CityDetailVC.h"
#import "LieHuaDetailVC.h"

@interface CityDetailVC () <UIWebViewDelegate>

@property (nonatomic, strong) UIWebView *webView;

@end

@implementation CityDetailVC

- (void)viewDidLoad {
    
    [super viewDidLoad];
    
    self.navTitleL.text = _moduleName;
    [self setFontSizeThatFits:self.navTitleL];
    [self createBlueNavigationBar:YES];
    
    [self creatWebView];
}

- (void)didReceiveMemoryWarning {
    
    [super didReceiveMemoryWarning];
}

- (void)creatWebView {
    
    self.webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, SafeAreaTopHeight, GET_SCREEN_WIDTH(), GET_SCREEN_HEIGHT()-SafeAreaTopHeight)];
    
    self.webView.backgroundColor = UICOLOR_HEX(0xffEDEEEF);
    
    self.webView.delegate = self;
    
    NSString * path = [[NSBundle mainBundle] pathForResource:@"/assets/hunan/html/zhibiaoshilingdao.html" ofType:nil];
    
    NSString *component = [NSString stringWithFormat:@"%@?cityName=%@&s_id=%@", path, _cityName, _s_id];
    
    NSString *encodedComponent = [component stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
    
    NSURL *fileUrl = [[NSURL alloc] initWithString:encodedComponent];
    
    NSURLRequest *request = [NSURLRequest requestWithURL:fileUrl];
    
    [self.webView loadRequest:request];
    
    [self.view addSubview:self.webView];
}

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
    // 获取点击页面加载的url
    NSString *url = request.URL.absoluteString;
    
    if ([url hasSuffix:@"shilingdao"]) {
        
        LieHuaDetailVC *vc = [[LieHuaDetailVC alloc] init];
        vc.moduleName = _moduleName;
        vc.cityName = _cityName;
        vc.s_id = _s_id;
        [self.navigationController pushViewController:vc animated:YES];
        
        return NO;
    }
    
    return YES;
}

@end
